package com.companyName.common.spec;

import com.companyName.common.log.LoggerHelper;
import com.companyName.common.message.MessageHelper;
import com.companyName.common.tx.ProgrammingTxHelper;
import com.companyName.common.tx.TransactionInfo;
import com.companyName.common.log.LogableDTO;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;

public abstract class AbsBusiSpec {
	
	private ProgrammingTxHelper programmingTxHelper;
	
	private MessageHelper maessageHelper;
	
	protected LoggerHelper logger = new LoggerHelper(getClass());
	
	public TransactionInfo beginTransaction(){
		return programmingTxHelper.beginTransaction();
	}
	
	public void commit(TransactionInfo tts) {
		programmingTxHelper.commit(tts);
	}

	public void commitAndBegin(TransactionInfo tts) {
		programmingTxHelper.commitAndBegin(tts);
	}

	public void rollback(TransactionInfo tts) {
		programmingTxHelper.rollback(tts);
	}

	public  void rollbackAndBegin(TransactionInfo tts) {
		programmingTxHelper.rollbackAndBegin(tts);
	}

	public void setRollBackupOnly(TransactionInfo tts) {
		programmingTxHelper.setRollBackupOnly(tts);
	}
	
	public void debug(LogableDTO obj, String str){
		logger.debug(obj, str);
	}
	
	public void debug(LogableDTO obj, String format, Object... arguments){
		logger.debug(obj, format, arguments);
	}
	
	public void debug(LogableDTO obj, String str, Throwable t){
		logger.debug(obj, str, t);
	}
	
	public void info(LogableDTO obj, String str){
		logger.info(obj, str);
	}
	
	public void info(LogableDTO obj, String format, Object... arguments){
		logger.info(obj, format, arguments);
	}
	
	public void info(LogableDTO obj, String str, Throwable t){
		logger.info(obj, str, t);
	}
	
	public void warn(LogableDTO obj, String str){
		logger.warn(obj, str);
	}
	
	public void warn(LogableDTO obj, String format, Object... arguments){
		logger.warn(obj, format, arguments);
	}
	
	public void warn(LogableDTO obj, String str, Throwable t){
		logger.warn(obj, str, t);
	}
	
	public void error(LogableDTO obj, String str){
		logger.error(obj, str);
	}
	
	public void error(LogableDTO obj, String format, Object... arguments){
		logger.error(obj, format, arguments);
	}
	
	public void error(LogableDTO obj, String str, Throwable t){
		logger.error(obj, str, t);
	}
	
	public void sendMessage(String exchangeId, String routeKey, Object message){
		maessageHelper.sendMessage(exchangeId, routeKey, message);
	}

	@Autowired
	public void setTxManager(DataSourceTransactionManager txManager) {
		programmingTxHelper = new ProgrammingTxHelper(txManager);
	}
	
	@Autowired
	public void setAmqpTemplate(AmqpTemplate amqpTemplate){
		maessageHelper = new MessageHelper(amqpTemplate);
	}
	
}
